package unittest.protein;

import java.util.ArrayList;
import java.util.List;

/**
 * 蛋白质变更记录追踪服务
 */
public class TrackingService {
    private int total;
    private int goal;
    private List<HistoryItem> history = new ArrayList<HistoryItem>();
    private int historyId = 0;

    /**
     * 增加蛋白质
     *
     * @param amount 增加的量
     */
    public void addProtein(int amount) {
        total += amount;
        history.add(new HistoryItem(historyId++, amount, "add", total));
    }

    /**
     * 减少蛋白质
     *
     * @param amount 减少的量
     */
    public void removeProtein(int amount) {
        total -= amount;
        if (total < 0) {
            total = 0;
        }
        history.add(new HistoryItem(historyId++, amount, "subtract", total));
    }

    /**
     * 获得当前总量
     */
    public int getTotal() {
        return total;
    }

    /**
     * 设置目标量
     */
    public void setGoal(int value) {
        goal = value;
    }

    /**
     * 当前总量是否到达目标量
     */
    public boolean isGoalMet() {
        return total >= goal;
    }

    /**
     * 获取全部历史记录
     */
    public List<HistoryItem> getHistory() {
        return history;
    }
}
